import request from '../axios'
var qs = require('qs')
// 上传图片
const upload = data => {
  console.log(data, 'axios data')
  return request({
    url: '/custom/owens/upload/image',
    method: 'post',
    data: qs.stringify(data),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

// 发送验证码
/**
 *
 * @param {mobile} data 手机号
 */
const verificationCode = data => {
  return request({
    url: '/custom/owens/verification-code',
    method: 'post',
    data: qs.stringify(data)
  })
}

// 获取所有年级列表
const gradesAll = data => {
  return request({
    url: '/custom/owens/grades/all',
    method: 'get',
    params: data
  })
}

// 视频上传的派发签名
const getSignature = () => {
  const obj = { Action: 'GetUgcUploadSign' }
  return new Promise((resolve, reject) => {
    request({
      url: '/custom/owens/video/signature',
      method: 'post',
      data: qs.stringify(obj)
    }).then(pos => {
      resolve(pos.signature)
    })
  })
}

// 根据就读年级获取组别
const getAssignGroup = data => {
  return request({
    url: `/custom/owens/grades/${data.grade}/group`,
    method: 'get'
  })
}

// 报名表达提交
/**
 *
 * @param {Content-Type} Headers
 */
const formSubmit = data => {
  return request({
    url: `/custom/owens/online/apply`,
    method: 'post',
    data: qs.stringify(data),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

export default {
  upload,
  verificationCode,
  gradesAll,
  getSignature,
  getAssignGroup,
  formSubmit
}
